package com.selune.online.ordering.system.project.customer.controller;

import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.api.pojo.user.customer.dto.CustomerLoginDTO;
import com.selune.online.ordering.system.project.api.pojo.user.customer.dto.CustomerUserDTO;
import com.selune.online.ordering.system.project.api.pojo.user.customer.dto.CustomerUserInfoDTO;
import com.selune.online.ordering.system.project.api.pojo.user.customer.vo.CustomerUserInfoVO;
import com.selune.online.ordering.system.project.api.pojo.user.dto.LoginDTO;
import com.selune.online.ordering.system.project.api.service.customer.ICustomerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author xiaoyp
 * @date 2020/3/22
 * <p>
 * Description: 消费者用户接口
 */
@RestController
@RequestMapping("/api/v1/ordering/customer/user")
@Slf4j
@Api(value = "消费者用户接口")
public class CustomerUserController {
	
	@Autowired
	private ICustomerUserService iCustomerUserService;
	
	@ApiOperation(value = "注册消费者用户", notes = "注册消费者用户")
	@ApiImplicitParam(name = "customerUserDTO", value = "用户信息DTO", required = true, dataType = "CustomerUserDTO", paramType = "body")
	@PostMapping(value = "/register", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> saveTenantUser(@RequestBody CustomerUserDTO customerUserDTO) {
		return iCustomerUserService.saveCustomerUser(customerUserDTO);
	}
	
	@ApiOperation(value = "编辑消费者用户信息", notes = "编辑消费者用户信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long", paramType = "query"),
		@ApiImplicitParam(name = "customerUserInfoDTO", value = "用户信息DTO", required = true, dataType = "CustomerUserInfoDTO", paramType = "body")
	})
	@PutMapping(value = "/update/user/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> updateCustomerUser(@PathVariable("userId") Long userId,
	                                            @RequestBody CustomerUserInfoDTO customerUserInfoDTO) {
		return iCustomerUserService.updateCustomerUser(userId, customerUserInfoDTO);
	}
	
	@ApiOperation(value = "编辑消费者登陆信息", notes = "编辑消费者登陆信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long", paramType = "query"),
		@ApiImplicitParam(name = "customerLoginDTO", value = "用户信息DTO", required = true, dataType = "CustomerLoginDTO", paramType = "body")
	})
	@PutMapping(value = "/update/login/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> updateCustomerLogin(@PathVariable("userId") Long userId,
	                                             @RequestBody CustomerLoginDTO customerLoginDTO) {
		return iCustomerUserService.updateCustomerLogin(userId, customerLoginDTO);
	}
	
	@ApiOperation(value = "根据用户名，密码登陆", notes = "根据用户名，密码登陆")
	@ApiImplicitParam(name = "loginDTO", value = "登陆DTO", required = true, dataType = "LoginDTO", paramType = "body")
	@PostMapping(value = "/login", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<CustomerUserInfoVO> userLogin(@RequestBody LoginDTO loginDTO) {
		return iCustomerUserService.userLogin(loginDTO);
	}
	
}
